package com.saicent.note.web.listener;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import com.saicent.note.core.ArticleManager;
import com.saicent.note.core.Configuration;
import com.saicent.note.core.ConfigurationBuilder;
import com.saicent.note.core.impl.ArticleManagerImpl;

public class ContextLoadListener implements ServletContextListener {

	@Override
	public void contextInitialized(ServletContextEvent contextEvent) {
		ConfigurationBuilder configurationBuilder = new ConfigurationBuilder(contextEvent.getServletContext().getRealPath("/"));
		Configuration configuration = configurationBuilder.build("notes.xml");
		ArticleManager articleManager = new ArticleManagerImpl(configuration);
		contextEvent.getServletContext().setAttribute(ArticleManager.class.getName(), articleManager);
	}

	@Override
	public void contextDestroyed(ServletContextEvent contextEvent) {
	}

}
